//
//  PrizeClawVideoHandler.hpp
//  MyApp
//
//  Created by Don on 2017/8/22.
//
//

#ifndef PrizeClawVideoHandler_hpp
#define PrizeClawVideoHandler_hpp

#ifdef __cplusplus
extern "C" {
#endif
    
#include "videodecode.h"
#include <stdio.h>

// 定义函数指针类型
typedef void (*FrameAvailableMessageHandler)(void *ref,uint8_t *);
typedef void (*FrameDidReadyMessageHandler)(void *ref,int videlWidth, int videoHeight,int glViewWidth, int glViewHeight);
typedef void (*FrameErrorMessageHandler)(void *ref,const int errorCode);

typedef void (*FrameStatusMessageHandler)(void *ref,int bitrate, int max_bitrate, int recv_pkts, int decoded_pkts, int discard_pkts);

class PrizeClawVideoHandler
{
    
public:
    ~PrizeClawVideoHandler();
    static PrizeClawVideoHandler* getInstance();
    
    
    void starPrizeClawVideo(const char* rtmp_ip, const char* id, int channel, int width, int height);
    void setCameraChannel(int channel);
    
    // 注册 视频帧 回调的函数
    void registerFrameAvailableCallBackFunction(void *,FrameAvailableMessageHandler);
    void registerFrameDidReadyCallBackFunction(void *,FrameDidReadyMessageHandler);
    void registerFrameErrorCallBackFunction(void *,FrameErrorMessageHandler);
    void registerFrameStatusCallBackFunction(void *,FrameStatusMessageHandler);
    
private:
    PrizeClawVideoHandler();
    //把复制构造函数和=操作符也设为私有,防止被复制
    PrizeClawVideoHandler(const PrizeClawVideoHandler&);
    PrizeClawVideoHandler& operator=(const PrizeClawVideoHandler&);
    
    CVideoDecoder *videoDecoder = NULL;
    // 要实现这个回调的对象
    void *ref = NULL;
    int screenWidth = 0;
    int screenHeight = 0;
    // 函数声明
    FrameAvailableMessageHandler frameAvailableHandler = NULL;
    FrameDidReadyMessageHandler frameDidReadyHandler = NULL;
    FrameErrorMessageHandler frameErrorHandler = NULL;
    FrameStatusMessageHandler frameStatusHandler = NULL;
    
    static void onFrameAvailable();
    static void onFrameDidReady(int width, int height);
    static void onFrameError(int error);
    static void onFrameStatus(int bitrate, int max_bitrate, int recv_pkts, int decoded_pkts, int discard_pkts);
    
    
//    void toggleCamera(int channel);
//    void closeVidel();
//    void initRender();
//    void initRenderFrame();
    
    
//    class CGarbo // 它的唯一工作就是在析构函数中删除PrizeClawVideoHandler的实例
//    {
//    public:
//        ~CGarbo()
//        {
//            if (PrizeClawVideoHandler::pcvInstance){
//                
//                delete PrizeClawVideoHandler::pcvInstance;
//                PrizeClawVideoHandler::pcvInstance = NULL;
//            }
//        }
//    };
//    static CGarbo Garbo; // 定义一个静态成员，在程序结束时，系统会调用它的析构函数
    
};

#ifdef __cplusplus
}
#endif

#endif /* PrizeClawVideoCallbackHandler_hpp */
